package com.fortune.service.impl;

import com.fortune.dao.DSalesmanSettingDao;
import com.fortune.dao.DdataAnalysisDao;
import com.fortune.dao.DealerStatisticsDao;
import com.fortune.dto.in.ddataAnalysisDto.DorderSummaryDto;
import com.fortune.dto.in.dealerStatistics.DriverOrderDto;
import com.fortune.entity.Driver;
import com.fortune.service.DealerStatisticsService;
import com.fortune.vo.dSalesmanSetting.DSalesmanSettingInfo;
import com.fortune.vo.ddateAnalysis.ClientPro;
import com.fortune.vo.ddateAnalysis.DdataProduct;
import com.fortune.vo.dealerStatistics.DriverOrder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/7/16 0016.
 */
@Service
public class DealerStatisticsServiceImpl  implements DealerStatisticsService{
    @Autowired
    private DealerStatisticsDao dealerStatisticsDao;
    @Autowired
    private DSalesmanSettingDao dSalesmanSettingDao;
    @Autowired
    private DdataAnalysisDao ddataAnalysisDao;

    @Override
    public List<DriverOrder> findDriverOrderList(String did, DriverOrderDto driverOrderDto) {
        return dealerStatisticsDao.findDriverOrderList(did,driverOrderDto);
    }

    @Override
    public List<DriverOrder> findMerchandisingList(String did, DriverOrderDto driverOrderDto) {
        List<DriverOrder> list = dealerStatisticsDao.findJXSPro(did,driverOrderDto);
        ////
        for(DriverOrder driver: list){
           int count  = dealerStatisticsDao.findProCount(did,driverOrderDto,driver.getId(),driver.getMid());
           driver.setCount(count);
        }
        return list;
    }

    @Override
    public int findMerchandisingListCount(String did, DriverOrderDto driverOrderDto) {
        List<DriverOrder> list = dealerStatisticsDao.findJXSProCount(did,driverOrderDto);
        int count = list.size();
       return count;
    }

    @Override
    public List<ClientPro> findOrderSummaryList(DorderSummaryDto dorderSummaryDto, String did) {
        List<ClientPro> list = ddataAnalysisDao.findOrderSummaryList(dorderSummaryDto,did); //查客户
        if(list.size()>0){
            for(ClientPro clientPro : list){
                float a = new Float(0);
                List<DdataProduct> list1 = ddataAnalysisDao.findMid(did);  //查MID
                List<DdataProduct> newList = new ArrayList<>();
                List<DdataProduct> list2 = ddataAnalysisDao.findPro2(did);
                for(DdataProduct ddataProduct2:list2){
                    newList.add(ddataProduct2);
                }
                for(DdataProduct ddataProduct:list1) {
                    List<DdataProduct> list3 = ddataAnalysisDao.findPro(ddataProduct.getMid());  //查mid下的商品
                    for(DdataProduct ddataProduct1:list3){
                        newList.add(ddataProduct1);
                    }
                }
                for(DdataProduct ddataProduct1 : newList){
                    Integer ddataProduct2 = ddataAnalysisDao.findNums(dorderSummaryDto,clientPro.getClientId(),ddataProduct1.getProId(),did);
                    if(ddataProduct2 == null){
                        ddataProduct1.setOrderNum(0);
                    }else{
                        ddataProduct1.setOrderNum(ddataProduct2);
                    }
                    a = a+ddataProduct1.getOrderNum();
                }
                clientPro.setProName(newList);
                clientPro.setCount(a);
            }
        }
        return list;
    }

    @Override
    public int findOrderSummaryListCount(String did) {
        return ddataAnalysisDao.findOrderSummaryListCount(did);
    }

}
